#ifndef GAMEKIT_SDL_SDLCANVAS_H
#define GAMEKIT_SDL_SDLCANVAS_H

#include "gamekit/gamekit.h"
#include "gamekit/common/AutoPointer.h"
#include "gamekit/drawing/Canvas.h"
#include "gamekit/drawing/Color.h"

#include "gamekit/sdl/SDLWindow.h"

namespace gamekit
{
	namespace sdl
	{
		class SDLSurface;

		class SDLCanvas : public Canvas
		{
		private:
			SDLCanvas(const SafePointer<SDLWindow>& window, const int& x, const int& y, const uint& width, const uint& height, const uint& bpp, const uint& zIndex);
			SDLCanvas(const SafePointer<SDLWindow>& window, const int& x, const int& y, const SafePointer<Bitmap>& canvas, const uint& zIndex);
		
		public:
			~SDLCanvas();

			void resize(const uint& width, const uint& height);
			void applyMask(SafePointer<Bitmap> mask);
			void fill(const Color& color, const uint& x, const uint& y, const uint& w, const uint& h);
			void draw(const SafePointer<Bitmap> bitmap, const int& x, const int& y);
			void draw(const unsigned int& elapsed);
			void init(const int& width, const int& height, const int& bpp);

		private:
			uint getPixel(SDL_Surface*, const int& x, const int& y);
			void setPixel(SDL_Surface*, const uint& pixel, const int& x, const int& y);
			Color getColor(SDL_Surface* surface, const uint& pixel);
			uint getPixel(SDL_Surface* surface, const Color& color);

		private:
			SafePointer<SDLWindow> m_window;
			AutoPointer<SDLSurface> m_surface;
		};
	}
}

#endif